<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>配置费率</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <form id="formSet1">
        <div class="fieldset1 tabel_col clearFix">
            <div class="fieldBox col_100_auto">
                <div class="label">方案编号</div>
                <div class="field">
                    <span>系统生成</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">机构名称</div>
                <div class="field">
                    <input name="orgNm" id="orgNm" type="text" value=""
                           placeholder="请选择" ltype="combobox">
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">业务</div>
                <div class="field">
                    <input name="busType" id="busType" type="text" value=""
                                                                     placeholder="请选择" ltype="combobox">
                </div>
            </div>
                <c:if test="${guaranteeType == '1'}">
                    <div class="fieldBox col_100_auto">
                        <div class="label">机构放款日期</div>
                        <div class="field">
                            <input ligerui="width: 120" name="orgPayBegin"
                                   id="orgPayBegin" type="text" class="ui-datepicker" value=""
                                   validate="{required:true}"> - <input
                                ligerui="width: 120" name="orgPayEnd" id="orgPayEnd"
                                type="text" class="ui-datepicker" value=""
                                validate="{required:true}">
                        </div>
                    </div>
                </c:if>
                <c:if test="${guaranteeType != '1'}">
                    <div class="fieldBox col_100_auto">
                        <div class="label">逾期天数</div>
                        <div class="field">
                            <input ligerui="width: 120" name="overdueBeginDay"
                                   id="overdueBeginDay" type="text" class="ui-textbox" value=""
                                   validate="{required:true}"> - <input
                                ligerui="width: 120" name="overdueEndDay" id="overdueEndDay"
                                type="text" class="ui-textbox" value=""
                                validate="{required:true}">
                        </div>
                    </div>
                </c:if>
            <div class="fieldBox col_100_auto">
                <div class="label">上报时间</div>
                <div class="field">
                    <input ligerui="width: 120" name="repBegin"
                           id="repBegin" type="text" class="ui-datepicker" value=""
                           validate="{required:true}"> - <input
                        ligerui="width: 120" name="repEnd" id="repEnd"
                        type="text" class="ui-datepicker" value=""
                        validate="{required:true}">
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">费率方式</div>
                <div class="field">
                    <select name="guarTypCd" id="guarTypCd" data-value=" ">
                        <option value=" " checked >请选择</option>
                        <option value="1">配置费率</option>
                        <option value="2">计算费率</option>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">费率</div>
                <div class="field">
                    <input name="repRate" id="repRate" type="text" class="ui-textbox"
                           value="" validate="{number:true}" placeholder="填写数字即可，支持小数点后两位">
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">有效期</div>
                <div class="field">
                    <input ligerui="width: 120" name="enableBegin"
                           id="enableBegin" type="text" class="ui-datepicker" value=""
                           validate="{required:true}"> - <input
                        ligerui="width: 120" name="enableEnd" id="enableEnd"
                        type="text" class="ui-datepicker" value=""
                        validate="{required:true}">
                </div>
            </div>
        </div>

        <div class="btnsBox">
            <span id="okBtn1" class="sq-button sq-button-round">保存</span>
            <span id="cancelBtn" class="sq-button sq-button-round">关闭</span>
        </div>
    </form>
</div>


<script type="text/javascript">
    $(function () {
        var formSet1 = $('#formSet1').ligerForm({
            validate: true
        });
        SET_popupIframeHeight();

    });

    $("#guarTypCd").change(function(){
        var guarTypCd = $("#guarTypCd").val();
        if("2" == guarTypCd){
            $('#repRate').ligerForm({
                disabled : true
            });
        }
        if("1" == guarTypCd){
            $('#repRate').ligerForm({
                disabled : false,
                validate : {required:true},
                //required : true
            });
        }
    })
    var _busTypeJson = ${busTypeJson};
    $("#busType").ligerComboBox({
        isShowCheckBox: true, isMultiSelect: true,
        data: _busTypeJson,
        valueField: 'key',
        textField: 'value',
    });

    //var comboGrid_defaultValue=""; //初始值(value)
    //var comboGrid_defaultText=""; //初始值(text)
    //var isInit_setSearchComboVal = false; //是否初始化的时候已经赋完初始值？

    var orgNms = [];

    //初始化机构选择
    var combo_orgNm = $("#orgNm").ligerComboBox({
        width: 400,
        selectBoxWidth: 380,
        selectBoxHeight: 240,
        valueField: 'id',
        textField: 'fundRasInsNm',
        isMultiSelect: true,
        grid: getGridOptions(true),
        condition: {
            labelWidth: 0,
            space: 5,
            fields: [{name: 'fundRasInsNm', width: 150, keyName: 'id'}]
        },
        delayLoadGrid: false,
        onChangeValue: function (value) {
            if (combo_orgNm) {
                //if (value=="") comboGrid_defaultValue = ""; //如果点击清空'x'，就滞空初始值
                orgNms = combo_orgNm.selected;
                $("#orgNm").show_ligerComboItems();
            }
            ;
            SetIframe_height();
            SET_popupIframeHeight();
        }
    });

    function getGridOptions(checkbox) {
        var url = '<%=path%>/fgi/fgiguarrate/initFriBaseInfoList.do?insSts=1&insUseCd=2'
        var options = {
            usePager: false,
            columns: [
                {display: '机构名称', name: 'fundRasInsNm', minWidth: 300}
            ],
            switchPageSizeApplyComboBox: false,
            url: url,
            method: 'get',
            dataAction: 'local',
            pageSize: 10,
            root: 'rows',
            record: 'total',
            usePagerOnLessPagesize: false,
            cssClass: "SMALL_grid",
            checkbox: checkbox,
            frozen: false,
            /*isSelected: function (rowdata) {
                if (comboGrid_defaultValue == "") return false;
                var defaultItems = comboGrid_defaultValue.split(";");
                if(!isInit_setSearchComboVal) { //只在初始化时执行一次，在onAfterShowData后改变
                    for (var i = 0; i < defaultItems.length; i++) {
                        if(rowdata[combo_orgNm.options.valueField] == defaultItems[i]) return true;
                    }
                }
                return false;
            },*/
            /*onAfterShowData: function (currentData) {
                if(!isInit_setSearchComboVal) { //只在初始化时执行一次，在onAfterShowData后改变
                    combo_orgNm.setInputValue("", comboGrid_defaultText, true);
                    isInit_setSearchComboVal = true;
                }
            }*/
        };
        return options;
    }


    $('#cancelBtn').click(function () {
        frameElement.dialog.close();
    });

    $('#okBtn1').click(function () {//确定
        var form = liger.get("formSet1");
        if (!form.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var data = form.getData();
        data.guaranteeType = '${guaranteeType }';
        data.orgNms = JSON.stringify(orgNms);
        //发送异步请求校验
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: '<%=path%>/fgi/fgiguarrate/add.do',
            beforeSend: function () {
                wait_dialog = top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    frameElement.dialog.close();
                } else if (msg.success == 0) {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    });
</script>
</body>
</html>
